package com.kaisu.blog.infrastructure.blog.convert;

import com.kaisu.blog.domain.blog.Blog;
import com.kaisu.blog.domain.blog.Comment;
import com.kaisu.blog.domain.blog.Like;
import com.kaisu.blog.infrastructure.blog.BlogPO;
import com.kaisu.blog.infrastructure.blog.CommentPO;
import com.kaisu.blog.infrastructure.blog.LikePO;
import com.kaisu.blog.infrastructure.blog.convert.decorated.BlogConvertDecorated;
import com.kaisu.blog.infrastructure.file.convert.FileConvert;
import com.kaisu.blog.infrastructure.user.convert.UserConvert;
import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;

/**
 * @author kaisu
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = {UserConvert.class, FileConvert.class})
@DecoratedWith(BlogConvertDecorated.class)
public interface BlogConvert {
    @Mapping(target = "cover", ignore = true)
    Blog toDomain(BlogPO po);

    @Mapping(target = "fileId", source = "cover.id")
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "status", source = "status.code")
    BlogPO toPO(Blog domain);

    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    CommentPO toPO(Comment domain);

    Comment toDomain(CommentPO po);

    @Mapping(target = "blog.updateTime", ignore = true)
    @Mapping(target = "blog.createTime", ignore = true)
    @Mapping(target = "blog.likes", ignore = true)
    @Mapping(target = "blog.fileId", ignore = true)
    LikePO map(Like like);

    @Mapping(target = "blog.likes", ignore = true)
    @Mapping(target = "blog.cover", ignore = true)
    Like map(LikePO like);
}
